package com.sharesrc.jdev.wiimotedemo.views;

import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

import org.wiigee.device.Wiimote;

import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
import wiiusej.wiiusejevents.physicalevents.IREvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
import wiiusej.wiiusejevents.utils.WiimoteListener;
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;

import com.sharesrc.jdev.wiimotedemo.common.constant.Constants;

public class WiimotePanel extends JPanel implements WiimoteListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 201308131042L;

	ImageIcon currentImg;

	public void setCurrentImg(ImageIcon currentImg) {
		this.currentImg = currentImg;
	}

	public WiimotePanel() {
		super();
		setOpaque(false);
		this.currentImg = Constants.Images.WIIMOTE_DISABLED;
		setPreferredSize(new Dimension(this.currentImg.getIconWidth(), this.currentImg.getIconHeight()));
	}

	@Override
	public final void paintComponent(Graphics graphics) {
		super.paintComponent(graphics);
		graphics.drawImage(this.currentImg.getImage(), 0, 0, this);
	}

	public void changeState(int button) {
		switch (button) {
		case Wiimote.BUTTON_2:// Button 2
			this.currentImg = Constants.Images.WIIMOTE_TWO_PRESSED;
			break;

		case Wiimote.BUTTON_1:// Button 1
			this.currentImg = Constants.Images.WIIMOTE_ONE_PRESSED;
			break;

		case Wiimote.BUTTON_B:// Button B
			this.currentImg = Constants.Images.WIIMOTE_B_PRESSED;
			break;

		case Wiimote.BUTTON_A:// Button A
			this.currentImg = Constants.Images.WIIMOTE_A_PRESSED;
			break;

		case Wiimote.BUTTON_MINUS:// Button MINUS
			this.currentImg = Constants.Images.WIIMOTE_MINUS_PRESSED;
			break;

		case Wiimote.BUTTON_HOME:// Button HOME
			this.currentImg = Constants.Images.WIIMOTE_HOME_PRESSED;
			break;

		case Wiimote.BUTTON_LEFT:// Button LEFT
			this.currentImg = Constants.Images.WIIMOTE_LEFT_PRESSED;
			break;

		case Wiimote.BUTTON_RIGHT:// Button RIGHT
			this.currentImg = Constants.Images.WIIMOTE_RIGHT_PRESSED;
			break;

		case Wiimote.BUTTON_DOWN:// Button DOWN
			this.currentImg = Constants.Images.WIIMOTE_DOWN_PRESSED;
			break;

		case Wiimote.BUTTON_UP:// Button UP
			this.currentImg = Constants.Images.WIIMOTE_UP_PRESSED;
			break;

		case Wiimote.BUTTON_PLUS:// Button PLUS
			this.currentImg = Constants.Images.WIIMOTE_PLUS_PRESSED;
			break;

		default:
			this.currentImg = Constants.Images.WIIMOTE;
			break;
		}

		repaint();
	}

	@Override
	public void onButtonsEvent(WiimoteButtonsEvent e) {
		changeState(e.getButtonsJustPressed());
	}

	@Override
	public void onIrEvent(IREvent e) {

	}

	@Override
	public void onMotionSensingEvent(MotionSensingEvent e) {

	}

	@Override
	public void onExpansionEvent(ExpansionEvent e) {

	}

	@Override
	public void onStatusEvent(StatusEvent e) {

	}

	@Override
	public void onDisconnectionEvent(DisconnectionEvent e) {

	}

	@Override
	public void onNunchukInsertedEvent(NunchukInsertedEvent e) {

	}

	@Override
	public void onNunchukRemovedEvent(NunchukRemovedEvent e) {

	}

	@Override
	public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent e) {

	}

	@Override
	public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent e) {

	}

	@Override
	public void onClassicControllerInsertedEvent(ClassicControllerInsertedEvent e) {

	}

	@Override
	public void onClassicControllerRemovedEvent(ClassicControllerRemovedEvent e) {

	}
}
